package main

import "fmt"

/*
go在创建结构体实例(变量)时，可以直接指定字段的值

创建结构体变量时指定字段值方式
(1)方式1
var stu Student = Student{"tom",10}
stu:=Student{"tom",10}
var stu Student = Student{
	Name:"mary",
	Age:10,
}
stu:=Student{
	Name:"mary",
	Age:10,
}
(2)方式2
var stu *Student = &Student{"smith",10}
var stu *Student = &Student{
	Name:"scott",
	Age:10,
}
*/
type Stu struct {
	Name string
	Age  int
}

func main() {
	//方式1
	//1、在创建结构体变量时，就直接指定字段的值
	var stu1 = Stu{"小明", 19}
	stu2 := Stu{"小明~", 20}
	//2、在创建结构体变量时，把字段名和字段值写在一起，这种写法，就不依赖字段的定义顺序
	var stu3 = Stu{
		Name: "jack",
		Age:  20,
	}
	stu4 := Stu{
		Name: "jack~",
		Age:  21,
	}
	fmt.Println(stu1, stu2, stu3, stu4)
	//方式2，返回结构体的指针类型
	var stu5 = &Stu{"小王", 29}
	//在创建结构体指针变量时，把字段名和字段值写在一起，这种写法，就不依赖字段的定义顺序
	stu6 := &Stu{"小王", 39}
	var stu7 = &Stu{
		Name: "小李",
		Age:  18,
	}
	stu8 := &Stu{
		Age:  19,
		Name: "小李",
	}
	fmt.Println(*stu5, *stu6, *stu7, *stu8)
}
